package com.pcbly.web.components.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

import com.pcbly.web.components.utils.validator.Validator;



public class DateUtils {

	public static long getOnlineInTime() {
		return System.currentTimeMillis() - 180000;
	}

	public static boolean isTodayTime(long atime) {
		Calendar cld = Calendar.getInstance();
		// cld.setTime(new Date());
		int year = cld.get(Calendar.YEAR);
		int month = cld.get(Calendar.MONTH);
		int day = cld.get(Calendar.DAY_OF_MONTH);
		Calendar todaycld = Calendar.getInstance();
		todaycld.set(year, month, day, 0, 0, 0);
		if (atime >= todaycld.getTime().getTime()) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Formats a Date as a fifteen character long String made up of the Date's
	 * padded millisecond value.
	 * 
	 * @return a Date encoded as a String.
	 */
	public static final String dateToMillis(Date date) {
		return LightsoftStringUtils.zeroPadString(Long.toString(date.getTime()), 15);
	}

	public static boolean isLastdayTime(long atime) {
		Calendar cld = Calendar.getInstance();
		// cld.setTime(new Date());
		cld.add(Calendar.DAY_OF_MONTH, -1);
		int year = cld.get(Calendar.YEAR);
		int month = cld.get(Calendar.MONTH);
		int day = cld.get(Calendar.DAY_OF_MONTH);
		Calendar lastdaycld = Calendar.getInstance();
		lastdaycld.set(year, month, day, 0, 0, 0);
		if (atime >= lastdaycld.getTime().getTime()) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean isTodayTime(long atime, String timeZone) {
		return isTodayTime(new Date(atime), timeZone);
	}

	public static boolean isYesterdayTime(long atime, String timeZone) {
		return isYesterdayTime(new Date(atime), timeZone);
	}

	public static boolean isTodayTime(Date atime, String timeZone) {
		Calendar cld = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		cld.set(Calendar.MILLISECOND, 0);
		int nowyear = cld.get(Calendar.YEAR);
		int nowmonth = cld.get(Calendar.MONTH);
		int nowday = cld.get(Calendar.DAY_OF_MONTH);

		Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		c.setTime(atime);
		c.set(Calendar.MILLISECOND, 0);
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day = c.get(Calendar.DAY_OF_MONTH);
		// int second = c.get(Calendar.SECOND);

		if (year == nowyear && month == nowmonth && day == nowday) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean isYesterdayTime(Date atime, String timeZone) {
		Calendar cld = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		cld.set(Calendar.MILLISECOND, 0);
		cld.add(Calendar.DAY_OF_MONTH, -1);
		int yyear = cld.get(Calendar.YEAR);
		int ymonth = cld.get(Calendar.MONTH);
		int yday = cld.get(Calendar.DAY_OF_MONTH);

		Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		c.setTime(atime);
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day = c.get(Calendar.DAY_OF_MONTH);
		// int second = c.get(Calendar.SECOND);

		if (year == yyear && month == ymonth && day == yday) {
			return true;
		} else {
			return false;
		}
	}

	public static String formatDateTime(Date date, String format) {
		SimpleDateFormat outFormat = new SimpleDateFormat(format);
		return outFormat.format(date);
	}

	public static String formatDateTime(Date date, String format,
			String timeZone) {
		// Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		// c.setTime(date);
		// c.set(Calendar.MILLISECOND, 0);
		SimpleDateFormat outFormat = new SimpleDateFormat(format);

		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(date.getTime());
		c.set(Calendar.MILLISECOND, 0);
		c.setTimeZone(TimeZone.getTimeZone(timeZone));
		return outFormat.format(c.getTime());
	}

	public static Date getLTDate(String date) {
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				Calendar cal = new GregorianCalendar();
				cal.set(Integer.parseInt(myDate[0]), Integer
						.parseInt(myDate[1]) - 1, Integer.parseInt(myDate[2]));
				return getLTDate(cal);
			}
		}
		Calendar cal = null;
		cal = new GregorianCalendar();
		return getLTDate(cal);
	}

	public static Date getGTDate(String date) {
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				Calendar cal = new GregorianCalendar();
				cal.set(Integer.parseInt(myDate[0]), Integer
						.parseInt(myDate[1]) - 1, Integer.parseInt(myDate[2]));
				return getGTDate(cal);
			}
		}
		Calendar cal = null;
		cal = new GregorianCalendar();
		return getGTDate(cal);
	}

	public static Date getLTDate(Calendar cal) {
		Calendar gtCal = (Calendar) cal.clone();
		gtCal.set(Calendar.HOUR_OF_DAY, 23);
		gtCal.set(Calendar.MINUTE, 59);
		gtCal.set(Calendar.SECOND, 59);
		gtCal.set(Calendar.MILLISECOND, 999);
		return gtCal.getTime();
	}

	public static Date getGTDate(Calendar cal) {
		Calendar gtCal = (Calendar) cal.clone();

		gtCal.set(Calendar.HOUR_OF_DAY, 0);
		gtCal.set(Calendar.MINUTE, 0);
		gtCal.set(Calendar.SECOND, 0);
		gtCal.set(Calendar.MILLISECOND, 0);

		return gtCal.getTime();
	}

	public static String getCurrTime() {
		Date now = new Date();
		SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String s = outFormat.format(now);
		return s;
	}

	public static String formatDate(Date date, String format) {
		SimpleDateFormat outFormat = new SimpleDateFormat(format);
		return outFormat.format(date);
	}

	/**
	 * Formats a Date object to return a date using the global locale.
	 */
	public static String formatDate(Date date) {
		SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-MM-dd");
		return outFormat.format(date);
	}

	/**
	 * Formats a Date object to return a date and time using the global locale.
	 */
	public static String formatDateTime(Date date) {
		SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return outFormat.format(date);
	}

	public static String formatDate2(Date myDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
		String strDate = formatter.format(myDate);
		return strDate;
	}

	public static String formatDate3(Date myDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm");
		String strDate = formatter.format(myDate);
		return strDate;
	}

	public static String formatDate4(Date myDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
		String strDate = formatter.format(myDate);
		return strDate;
	}

	public static String formatDate5(Date myDate) {
		String strDate = getYear(myDate) + "-" + getMonth(myDate) + "-"
				+ getDay(myDate);
		return strDate;
	}

	public static String formatDate6(Date myDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String strDate = formatter.format(myDate);
		return strDate;
	}

	public static long Date2Long(int year, int month, int date) {
		Calendar cld = Calendar.getInstance();
		month = month - 1;
		cld.set(year, month, date);
		return cld.getTime().getTime();
	}

	public static long Time2Long(int year, int month, int date, int hour,
			int minute, int second) {
		Calendar cld = Calendar.getInstance();
		month = month - 1;
		cld.set(year, month, date, hour, minute, second);
		return cld.getTime().getTime();
	}

	public static int getYear(long t) {
		Calendar cld = Calendar.getInstance();
		if (t > 0) {
			cld.setTime(new java.util.Date(t));
		}
		return cld.get(Calendar.YEAR);
	}

	public static int getMonth(long t) {
		Calendar cld = Calendar.getInstance();
		if (t > 0) {
			cld.setTime(new java.util.Date(t));
		}
		return cld.get(Calendar.MONTH) + 1;
	}

	public static int getDay(long t) {
		Calendar cld = Calendar.getInstance();
		if (t > 0) {
			cld.setTime(new java.util.Date(t));
		}
		return cld.get(Calendar.DAY_OF_MONTH);
	}

	public static int getHour(long t) {
		Calendar cld = Calendar.getInstance();
		if (t > 0) {
			cld.setTime(new java.util.Date(t));
		}
		return cld.get(Calendar.HOUR_OF_DAY);
	}

	public static int getMinute(long t) {
		Calendar cld = Calendar.getInstance();
		if (t > 0) {
			cld.setTime(new java.util.Date(t));
		}
		return cld.get(Calendar.MINUTE);
	}

	public static int getSecond(long t) {
		Calendar cld = Calendar.getInstance();
		if (t > 0) {
			cld.setTime(new java.util.Date(t));
		}
		return cld.get(Calendar.SECOND);
	}

	public static int getYear(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.YEAR);
	}

	public static int getMonth(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.MONTH) + 1;
	}

	public static int getDay(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.DAY_OF_MONTH);
	}

	public static int getHour(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.HOUR_OF_DAY);
	}

	public static int getMinute(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.MINUTE);
	}

	public static int getSecond(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.SECOND);
	}

	public static int getYear() {
		Calendar cld = Calendar.getInstance();
		cld.setTime(new java.util.Date());
		return cld.get(Calendar.YEAR);
	}

	public static int getMonth() {
		Calendar cld = Calendar.getInstance();
		cld.setTime(new java.util.Date());
		return cld.get(Calendar.MONTH) + 1;
	}

	public static int getDay() {
		Calendar cld = Calendar.getInstance();
		cld.setTime(new java.util.Date());
		return cld.get(Calendar.DAY_OF_MONTH);
	}

	public static String replaceComma(String text) {
		if (text != null) {
			text = text.replaceAll("，", ",");
		}
		return text;
	}

	public static String replaceBr(String text) {
		if (text != null) {
			text = text.replaceAll("\n", "<BR>");
		}
		return text;
	}

	public static long getLongTime() {
		return System.currentTimeMillis();
	}

	public static Date getDateTime(String date, String hour, String minute) {// yyyy-mm-dd
		// hh
		// mm
		if (Validator.isDate(date)) {
			hour = (Validator.isDigit(hour)) ? hour : "0";
			minute = (Validator.isDigit(minute)) ? minute : "0";
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				return getDateTime(Integer.parseInt(myDate[0]), Integer
						.parseInt(myDate[1]), Integer.parseInt(myDate[2]),
						Integer.parseInt(hour), Integer.parseInt(minute));
			}
		}
		return new Date();
	}

	public static Date getDate(String date) {// yyyy-mm-dd
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				return getDate(Integer.parseInt(myDate[0]), Integer
						.parseInt(myDate[1]), Integer.parseInt(myDate[2]));
			}
		}
		return new Date();
	}

	public static Date getDateTwo(String date) {// yyyy-mm-dd
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				return getDate(Integer.parseInt(myDate[0]), Integer
						.parseInt(myDate[1]), Integer.parseInt(myDate[2]));
			}
		}
		return null;
	}

	public static Date getDate(int year, int month, int day) {
		Calendar cal = null;
		cal = new GregorianCalendar();
		cal.set(year, month - 1, day);
		Date date = cal.getTime();
		return date;
	}

	public static Date getDateTime(int year, int month, int day, int hour,
			int minute) {
		Calendar cal = null;
		cal = new GregorianCalendar();
		cal.set(year, month - 1, day, hour, minute, 0);
		Date date = cal.getTime();

		return date;
	}

	public static Date getDate(String year, String month, String day) {
		int l_intYear = 0;
		int l_intMonth = 0;
		int l_intDate = 0;
		if (Validator.isNumber(year))
			l_intYear = Integer.parseInt(year);
		if (Validator.isNumber(month))
			l_intMonth = Integer.parseInt(month);
		if (Validator.isNumber(day))
			l_intDate = Integer.parseInt(day);

		Calendar cal = null;
		cal = new GregorianCalendar();
		cal.set(l_intYear, l_intMonth - 1, l_intDate);
		Date date = cal.getTime();
		return date;
	}

	public static Date stringParseToDateTime(String str) {
		if (Validator.isNotNull(str)) {
			// DateFormat
			// df=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			try {
				Date date = df.parse(str);
				return date;
			} catch (ParseException e) {
				// e.printStackTrace();
				return new Date();
			}

		}
		return new Date();
	}

	/**
	 * 3/29/2006 jovan
	 * 
	 * @param fullDate
	 * @return
	 */
	public static String convertDateDisplayFormat(String fullDate) {
		String l_strYear;
		String l_strMonth;
		String l_strDate;
		String l_strDisplayDate;
		if (fullDate == null || fullDate == "")
			return fullDate;
		String[] myDate = LightsoftStringUtils.split(fullDate, "-");
		if (myDate != null && myDate.length == 3) {
			l_strYear = myDate[0];
			l_strMonth = myDate[1];
			l_strDate = myDate[2];
		} else {
			return null;
		}
		l_strDisplayDate = l_strYear + "-" + l_strMonth + "-" + l_strDate;
		if (l_strYear.equals("1900"))
			l_strDisplayDate = "";
		return l_strDisplayDate;
	}

	/**
	 * 3/29/2006 jovan
	 * 
	 * @param fullDate
	 * @return
	 */
	public static String convertDateDisplayFormat(Date fullDate) {
		if (fullDate == null)
			return null;
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String l_strDisplayDate = df.format(fullDate);
		/*
		 * String l_strYear =String.valueOf(fullDate.getYear()); String
		 * l_strMonth =String.valueOf(fullDate.getMonth()); String l_strDate
		 * =String.valueOf(fullDate.getDay()); String l_strDisplayDate ;
		 * l_strDisplayDate = l_strYear + "-" + l_strMonth + "-" + l_strDate ;
		 * if (l_strYear.equals("1900")||l_strYear.equals("0000"))
		 * l_strDisplayDate="";
		 */
		return l_strDisplayDate;
	}

	/**
	 * 3/29/2006 jovan
	 * 
	 * @param fullDate
	 * @return
	 */
	public static String convertDateDisplayFormat(Date fullDate,
			String formatstr) {
		if (fullDate == null)
			return null;
		DateFormat df = new SimpleDateFormat(formatstr);
		String l_strDisplayDate = df.format(fullDate);
		/*
		 * String l_strYear =String.valueOf(fullDate.getYear()); String
		 * l_strMonth =String.valueOf(fullDate.getMonth()); String l_strDate
		 * =String.valueOf(fullDate.getDay()); String l_strDisplayDate ;
		 * l_strDisplayDate = l_strYear + "-" + l_strMonth + "-" + l_strDate ;
		 * if (l_strYear.equals("1900")||l_strYear.equals("0000"))
		 * l_strDisplayDate="";
		 */
		return l_strDisplayDate;
	}

	/**
	 * 20060421,added by Lingjingzhong
	 * */
	public static String cutHHMMSS(String fullDateIncludingHHMMSS) {
		String l_strYear;
		String l_strMonth;
		String l_strDate;
		String l_strDisplayDate;
		if (fullDateIncludingHHMMSS == null
				|| "".equals(fullDateIncludingHHMMSS)) {
			return fullDateIncludingHHMMSS;
		}

		String[] tempDate = LightsoftStringUtils.split(fullDateIncludingHHMMSS, "-");
		if (tempDate != null && tempDate.length == 3) {
			l_strYear = tempDate[0];
			l_strMonth = tempDate[1];
			l_strDate = tempDate[2].substring(0, 2);
		} else {
			return null;
		}
		l_strDisplayDate = l_strYear + "-" + l_strMonth + "-" + l_strDate;
		if (l_strYear.equals("1900")) {
			l_strDisplayDate = "";
		}
		return l_strDisplayDate;
	}

	public static String getNextDate(String date) {// yyyy-mm-dd
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);

				Calendar cal = null;
				cal = new GregorianCalendar();
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				cal.add(Calendar.DATE, 1);
				Date nextday = cal.getTime();
				return convertDateDisplayFormat(nextday);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getPreDate(String date) {// yyyy-mm-dd

		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);

				Calendar cal = null;
				cal = new GregorianCalendar();
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				cal.add(Calendar.DATE, -1);
				Date nextday = cal.getTime();
				return convertDateDisplayFormat(nextday);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	// get the day's name according a date
	public static String getWeek(String date) {// yyyy-mm-dd
		String[] DAYS_ABBREVIATION = new String[] { "sunday", "monday",
				"tuesday", "wednesday", "thursday", "friday", "saturday" };
		Calendar cal = new GregorianCalendar();
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
			}
		}
		// 1--7
		return DAYS_ABBREVIATION[cal.get(Calendar.DAY_OF_WEEK) - 1];

	}

	public static String getNextWeekFirstDate(String date) {// yyyy-mm-dd
		Calendar cal = new GregorianCalendar();
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				cal.add(Calendar.DAY_OF_MONTH, 7);
				int dayofweek = cal.get(Calendar.DAY_OF_WEEK) - 1;
				cal.add(Calendar.DAY_OF_MONTH, -dayofweek);

				Date nextWeekDate = cal.getTime();
				return convertDateDisplayFormat(nextWeekDate);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getNextWeekLastDate(String date) {// yyyy-mm-dd
		Calendar cal = new GregorianCalendar();
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				cal.add(Calendar.DAY_OF_MONTH, 7);
				int dayofweek = 7 - cal.get(Calendar.DAY_OF_WEEK);
				cal.add(Calendar.DAY_OF_MONTH, dayofweek);

				Date nextWeekDate = cal.getTime();
				return convertDateDisplayFormat(nextWeekDate);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getPreWeekFirstDate(String date) {// yyyy-mm-dd
		Calendar cal = new GregorianCalendar();
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				cal.add(Calendar.DAY_OF_MONTH, -7);
				int dayofweek = cal.get(Calendar.DAY_OF_WEEK) - 1;
				cal.add(Calendar.DAY_OF_MONTH, -dayofweek);

				Date nextWeekDate = cal.getTime();
				return convertDateDisplayFormat(nextWeekDate);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getPreWeekLastDate(String date) {// yyyy-mm-dd
		Calendar cal = new GregorianCalendar();
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				cal.add(Calendar.DAY_OF_MONTH, -7);
				int dayofweek = 7 - cal.get(Calendar.DAY_OF_WEEK);
				cal.add(Calendar.DAY_OF_MONTH, dayofweek);

				Date nextWeekDate = cal.getTime();
				return convertDateDisplayFormat(nextWeekDate);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getCurWeekFirstDate(String date) {// yyyy-mm-dd
		Calendar cal = new GregorianCalendar();
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				// cal.add(Calendar.DAY_OF_MONTH,-7);
				int dayofweek = cal.get(Calendar.DAY_OF_WEEK) - 1;
				cal.add(Calendar.DAY_OF_MONTH, -dayofweek);

				Date nextWeekDate = cal.getTime();
				return convertDateDisplayFormat(nextWeekDate);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getCurWeekLastDate(String date) {// yyyy-mm-dd
		Calendar cal = new GregorianCalendar();
		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				// cal.add(Calendar.DAY_OF_MONTH,-7);
				int dayofweek = 7 - cal.get(Calendar.DAY_OF_WEEK);
				cal.add(Calendar.DAY_OF_MONTH, dayofweek);
				Date nextWeekDate = cal.getTime();
				return convertDateDisplayFormat(nextWeekDate);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getNextMonthDate(String date) {// yyyy-mm-dd

		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);

				Calendar cal = null;
				cal = new GregorianCalendar();
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				cal.add(Calendar.MONTH, 1);
				Date nextday = cal.getTime();

				return convertDateDisplayFormat(nextday);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getPreMonthDate(String date) {// yyyy-mm-dd

		if (Validator.isDate(date)) {
			String[] myDate = LightsoftStringUtils.split(date, "-");
			if (myDate != null && myDate.length == 3) {
				int l_intYear = 0;
				int l_intMonth = 0;
				int l_intDate = 0;
				if (Validator.isNumber(myDate[0]))
					l_intYear = Integer.parseInt(myDate[0]);
				if (Validator.isNumber(myDate[1]))
					l_intMonth = Integer.parseInt(myDate[1]);
				if (Validator.isNumber(myDate[2]))
					l_intDate = Integer.parseInt(myDate[2]);

				Calendar cal = null;
				cal = new GregorianCalendar();
				cal.set(l_intYear, l_intMonth - 1, l_intDate);
				cal.add(Calendar.MONTH, -1);
				Date nextday = cal.getTime();
				return convertDateDisplayFormat(nextday);
			}
		}
		return convertDateDisplayFormat(new Date());
	}

	public static String getYear(String fullDate) {
		String[] myDate = LightsoftStringUtils.split(fullDate, "-");
		return myDate[0];
	}

	public static String getMonth(String fullDate) {
		String[] myDate = LightsoftStringUtils.split(fullDate, "-");
		return myDate[1];
	}

	public static String getDay(String fullDate) {
		String[] myDate = LightsoftStringUtils.split(fullDate, "-");
		return myDate[2];
	}

	/**
	 * @author Ling Jingzhong switch the yyyy-MM-dd to yyyyMMdd
	 * */
	public static String getIntTypeDate(String fullDate) {
		String[] date = LightsoftStringUtils.split(fullDate, "-");
		return date[0] + date[1] + date[2];
	}

	public static String getFirstDateOfCurMonth(String date) {// yyyy-MM-dd
		String[] dateStr = LightsoftStringUtils.split(date, "-");
		return dateStr[0] + "-" + dateStr[1] + "-" + "01";
	}

	/**
	 * @author Ling Jingzhong, 20061030
	 * @return String, the type is "yyyy-MM-dd"
	 * */
	public static String getLastDateOfCurMonth(String date) {
		Calendar calendar = new GregorianCalendar();
		calendar.clear();
		calendar.set(Calendar.YEAR, Integer.parseInt(getYear(date)));
		calendar.set(Calendar.MONTH, Integer.parseInt(getMonth(date)) - 1);
		calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));

		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = df.format(calendar.getTime());
		return dateStr;
	}

	public static String getLastDateOfPreMonth(String date) {
		Calendar calendar = new GregorianCalendar();
		calendar.clear();
		calendar.set(Calendar.YEAR, Integer.parseInt(getYear(date)));
		calendar.set(Calendar.MONTH, Integer.parseInt(getMonth(date)) - 2);
		calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));

		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = df.format(calendar.getTime());
		return dateStr;
	}

	public static String getFirstDateOfPreMonth(String date) {
		Calendar calendar = new GregorianCalendar();
		calendar.clear();
		calendar.set(Calendar.YEAR, Integer.parseInt(getYear(date)));
		calendar.set(Calendar.MONTH, Integer.parseInt(getMonth(date)) - 2);
		calendar.set(Calendar.DATE, 1);

		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = df.format(calendar.getTime());
		return dateStr;
	}

	public static String getFirstDateOfNextMonth(String date) {
		Calendar calendar = new GregorianCalendar();
		calendar.clear();
		calendar.set(Calendar.YEAR, Integer.parseInt(getYear(date)));
		calendar.set(Calendar.MONTH, Integer.parseInt(getMonth(date)));
		calendar.set(Calendar.DATE, 1);

		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = df.format(calendar.getTime());
		return dateStr;
	}

	public static int getCurWeekOfYear(String date) {
		Calendar calendar = new GregorianCalendar();
		calendar.clear();
		calendar.set(Calendar.YEAR, Integer.parseInt(getYear(date)));
		calendar.set(Calendar.MONTH, Integer.parseInt(getMonth(date)) - 1);
		calendar.set(Calendar.DATE, Integer.parseInt((date.split("-"))[2]));
		return calendar.get(Calendar.WEEK_OF_YEAR);
	}

	/**
	 *date's type is yyyy-MM-dd decide a date is Sunday(==1), or Monday(==2),
	 * or Tuesday(==3),...
	 * */
	public static int getDayOfWeek(String date) {
		Calendar calendar = new GregorianCalendar();
		calendar.clear();
		calendar.set(Calendar.YEAR, Integer.parseInt(getYear(date)));
		calendar.set(Calendar.MONTH, Integer.parseInt(getMonth(date)) - 1);
		calendar.set(Calendar.DATE, Integer.parseInt((date.split("-"))[2]));
		return calendar.get(Calendar.DAY_OF_WEEK);
	}

	public static int getCurWeekOfMonth(String date) {
		Calendar calendar = new GregorianCalendar();
		calendar.clear();
		calendar.set(Calendar.YEAR, Integer.parseInt(getYear(date)));
		calendar.set(Calendar.MONTH, Integer.parseInt(getMonth(date)) - 1);
		calendar.set(Calendar.DATE, Integer.parseInt((date.split("-"))[2]));
		return calendar.get(Calendar.WEEK_OF_MONTH);
	}

	public static String getHhMmStringFromFullDateTime(Date dateAndTime) {// input
		// type:fullDate,
		// as
		// "yyyy-MM-dd hh:mm:ss"
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(dateAndTime);

		String hh = Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
		String mm = Integer.toString(calendar.get(Calendar.MINUTE));
		if (hh.length() == 1) {
			hh = "0" + hh;
		}
		if (mm.length() == 1) {
			mm = "0" + mm;
		}
		return hh + ":" + mm;
	}

	// input type: fullDate, as "yyyy-MM-dd hh:mm:ss"
	public static String getHhMmSsStringFromFullDateTime(Date dateAndTime) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(dateAndTime);
		String hh = Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
		String mm = Integer.toString(calendar.get(Calendar.MINUTE));
		String ss = Integer.toString(calendar.get(Calendar.SECOND));
		if (hh.length() == 1) {
			hh = "0" + hh;
		}
		if (mm.length() == 1) {
			mm = "0" + mm;
		}
		if (ss.length() == 1) {
			ss = "0" + ss;
		}
		return hh + ":" + mm + ":" + ss;
	}

}
